package com.newzqxq.common.utils.pay;

import org.springframework.util.Base64Utils;
import org.springframework.util.StringUtils;

import java.util.Base64;

/**
 * @author 石清
 * @Description  xendit签名校验工具
 * @create 2017-12-06 10:09
 **/
public class XenditSignUtil {

    /**
     * 每次提交api请求都会把prikey拿来签名
     * @param priKey
     * @return
     */
     public static String sign(String priKey) throws Exception{
         if (StringUtils.isEmpty(priKey)){
             throw new IllegalArgumentException("缺少参数prikey");
         }
         priKey+=":";
         byte[] bytes=Base64Utils.encode(priKey.getBytes());
         return "Basic "+new String(bytes);
     }

    public static void main(String[] args) throws Exception {
         String priKey="xnd_development_PYGEfL0kgbeowJE8LOEbHjPDY9fx8NB6kiHm+Rxi/W3W+L2nDAB2gg==";
         priKey="xnd_production_OYGJfL0kgbeowJE8LOEbHjPDY9fx8NB6kiHm+Rxi/W3W+L2nDAB2hw==";
        String str=sign(priKey);
        System.out.println(str);
    }
}
